home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TTrash.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  4.4 KB  |  124 lines  |  [TEXT/MPS ]

  1. #pragma segment trash
  2. // **********************************************************************
  3. //    TTrash - Methods
  4. // **********************************************************************
  5. void TCTrash::ICTrash(Point cornor, short itsRsrsId,short itsVSize,short itsHSize,
  6.     short itsMaxSize,short side)
  7.     {
  8.     fRsrsId = itsRsrsId;
  9.  
  10.     theIcon = GetCIcon(itsRsrsId);                                                // get icon from resource
  11.     if (theIcon == NULL)                                                                // not gotten
  12.         { return;}                                                                            // LAM - error handling
  13.     
  14.     HLock((Handle) theIcon);                                                        // lock the handle
  15.     HLock((Handle) this);
  16.     this->CalcLocation(&cornor,itsVSize,itsHSize,itsMaxSize,side);    // Center the icon over the point if possible
  17.     HUnlock((Handle) this);
  18.     
  19.     fCTrash.top         = cornor.v;                                                    // create
  20.     fCTrash.left        = cornor.h;
  21.     fCTrash.bottom    = cornor.v + itsVSize;
  22.     fCTrash.right    = cornor.h + itsHSize;
  23.     return;
  24.     }
  25.  
  26. // --------------------------------------------------------------------------------------------------
  27. //    Free the icon handle
  28. // --------------------------------------------------------------------------------------------------
  29. pascal void TCTrash::Free(void)
  30.     {
  31.     DisposCIcon(theIcon);
  32.     HUnlock((Handle) theIcon);
  33.     inherited::Free();
  34.     }
  35.     
  36. // --------------------------------------------------------------------------------------------------
  37. //    Is mouse inside the trash can icon?
  38. // --------------------------------------------------------------------------------------------------
  39. Boolean TCTrash::InTheCan(Point theMouse)
  40.     {
  41.     Boolean t;
  42.     HLock((Handle) this);
  43.     t = PtInRect(theMouse,&fCTrash);
  44.     HUnlock((Handle) this);
  45.     
  46.     return t;
  47.     }
  48.     
  49. // --------------------------------------------------------------------------------------------------
  50. //    Draw the Trash can icon
  51. // --------------------------------------------------------------------------------------------------
  52. pascal void TCTrash::DrawCan(void)
  53.     {
  54.     PenMode(srcXor);
  55.     HLock((Handle) this);
  56.     PlotCIcon(&fCTrash,theIcon);
  57.     HUnlock((Handle) this);
  58.     }
  59.  
  60. // --------------------------------------------------------------------------------------------------
  61. //    Draw the Trash can icon
  62. // --------------------------------------------------------------------------------------------------
  63. Rect TCTrash::GetRect(void)
  64.     {
  65.     return fCTrash;
  66.     }
  67.  
  68. // --------------------------------------------------------------------------------------------------
  69. //    Calculate the location of the upper left cornor of the trash can
  70. // --------------------------------------------------------------------------------------------------
  71. void TCTrash::CalcLocation(Point * cornor,short itsVSize,short itsHSize,short itsMaxSize,short side)
  72.     {
  73.     short cVert, cHorz, test2;
  74.  
  75.     if (side == 1 || side == 3)                                                        // point on right / left
  76.         {
  77.         cVert    = (itsVSize/2) + 1;                                                // find half way
  78.         cornor->v -= cVert;                                                            // center vertically
  79.         test2    = itsMaxSize - (cornor->v + cVert);                        // calc difference from bottom
  80.         if (cornor->v < 0)                                                                // beyond top ?
  81.             cornor->v = 0;
  82.         else if (test2 < 0)                                                                // beyond bottom?
  83.             cornor->v += test2;
  84.         
  85.         if (side == 3)                                                                    // place point on the right
  86.             {
  87.             cornor->h -= (itsHSize - gPensize_H);                            // calc far left cornor
  88.             if (cornor->h < 0)
  89.                 cornor->h = 0;                                                            // don't allow off window
  90.             }
  91.         else                                                                                    // place point on the left
  92.             {
  93.             cornor->h -= gPensize_H;
  94.             test2 = itsMaxSize - (cornor->h + itsHSize);                // calc for right cornor
  95.             if (test2 < 0)                                                                // beyond right side
  96.                 cornor->h += test2;
  97.             }
  98.         }
  99.     else                                                                                        // point on bottom / top
  100.         {
  101.         cHorz    = (itsHSize/2) + 1;                                                // find half way
  102.         cornor->h -= cHorz;                                                            // center horizontally
  103.         test2    = itsMaxSize - (cornor->h + cHorz);                        // calc difference from left
  104.         if (cornor->h < 0)                                                                // beyond top?
  105.             cornor->h = 0;
  106.         else if (test2 < 0)                                                                // beyond bottom?
  107.             cornor->h += test2;
  108.  
  109.         if (side == 0)                                                                    // place point on the bottom
  110.             {
  111.             cornor->v -= (itsVSize - gPensize_V);                            // calc far left cornor
  112.             if (cornor->v < 0)
  113.                 cornor->v = 0;                                                            // don't allow off window
  114.             }
  115.         else                                                                                    // place point on the left
  116.             {
  117.             cornor->v -= gPensize_V;
  118.             test2 = itsMaxSize - (cornor->v + itsVSize);                // calc for right cornor
  119.             if (test2 < 0)                                                                // beyond right side
  120.                 cornor->v += test2;
  121.             }
  122.         }
  123.     return;
  124.     }